package cn.edu.scau.cmi.zenghanxiong.adapter;

import java.util.ArrayList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.TextArea;

public class AdapterController {
	@FXML
	private Button myButton;
	@FXML
	private TextField Name;
	@FXML
	private TextField Number;
	@FXML
	private TextArea myText,objectText; 
	
	ArrayList<classAdapter> stu=new ArrayList<classAdapter>();
	ArrayList<Integer> nums=new ArrayList<Integer>();
	ArrayList<objectAdapter> obstu=new ArrayList<objectAdapter>();
	ArrayList<Integer> obnums=new ArrayList<Integer>();
	
	public void showStudent(ActionEvent event) {
		//classAdapter
		myText.setText("");
		classAdapter student=new classAdapter();
		String name=Name.getText();
		String number=Number.getText();
		student.setName(name);
		student.setNumber(number);
		nums.add(Integer.parseInt(number));
		stu.add(student);
		student.sortInt(nums);
		myText.appendText("classAdapter:\n");
		for(int i=0;i<nums.size();i++) {	
			for(int j=0;j<stu.size();j++) {
				if(nums.get(i)==Integer.parseInt(stu.get(j).getNumber())) {
					myText.appendText(stu.get(j).getNumber()+" "+stu.get(j).getName()+'\n');
					break;
				}
			}	
		}
		//objectAdapter
		objectText.setText("");;
		objectAdapter obstudent=new objectAdapter();
		obstudent.setName(name);
		obstudent.setNumber(number);
		obnums.add(Integer.parseInt(number));
		obstu.add(obstudent);
		obstudent.sortInt(obnums);
		objectText.appendText("objectAdapter:\n");
		for(int i=0;i<obnums.size();i++) {	
			for(int j=0;j<obstu.size();j++) {
				if(obnums.get(i)==Integer.parseInt(obstu.get(j).getNumber())) {
					objectText.appendText(obstu.get(j).getNumber()+" "+obstu.get(j).getName()+'\n');
					break;
				}
			}	
		}
		Name.setText("");
		Number.setText("");
	}
}